package com.acme.domain.bank;

public class Client {

	private Account account;
	private String name;
	private Gender gender;
	
	public Client(Account account, String name, Gender gender) {
		super();
		this.account = account;
		this.name = name;
		this.gender = gender;
	}

	public Account getAccount() {
		return account;
	}

	public String getSalutation(){
		StringBuffer stb = new StringBuffer();
		stb.append(gender);
		stb.append(" ");
		stb.append(name);
		return stb.toString();
	}
	
	public String getName() {
		return name;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null) return false;
		if(this == obj)	return true;
		if(this.hashCode() != obj.hashCode()) return false;
		final Client other = (Client) obj;
		if(! this.name.equals(other.getName()) ) return false;
		if(! (this.account.getBalance() == other.getAccount().getBalance()) ) return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int value = 23;
		int result = 13;
		result = value * name.length() + ((int) account.getBalance())*gender.toString().length();
		return result;
	}

	@Override
	public String toString() {
		StringBuffer stb = new StringBuffer(getSalutation());
		stb.append(" balance = ");
		stb.append(account.getBalance());
		return stb.toString();
	}
	
}
